//
//  BCLogInViewController.m
//  BangcaiBuy
//
//  Created by lsy on 16/6/13.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCLogInViewController.h"
#import "BCRegisterViewController.h"
#import "BCFindPassViewController.h"
#import "AppDelegate.h"
@implementation BCLogInViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
    

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}
- (void)getView{
    self.loginView = [[BClogInView alloc] initWithFrame:self.view.frame backImage:[UIImage imageNamed:@"logo-1"]];
    [self getTarget];
    self.loginView.phoneNum.text = @"13812345678";
    self.loginView.passWord.text = @"2";
   
    [self numJuge];
    [self.loginView.phoneNum addTarget:self action:@selector(numJuge) forControlEvents:UIControlEventEditingDidEnd];
    [self.loginView.passWord addTarget:self action:@selector(numJuge) forControlEvents:UIControlEventEditingDidEnd];
    [self.view addSubview:self.loginView];
    
}

- (void)numJuge{
    if ([self canLog]) {
        self.loginView.logIn.backgroundColor = [UIColor colorWithRed:0.201  green:0.684  blue:0.338 alpha:1];
        self.loginView.logIn.userInteractionEnabled = YES;

    }else{
        self.loginView.logIn.backgroundColor = [UIColor colorWithRed:0.601  green:0.843  blue:0.665 alpha:1];
        self.loginView.logIn.userInteractionEnabled = NO;
    }

}

- (void)getTarget
{
    [self.loginView.logIn addTarget:self action:@selector(goLogIn) forControlEvents:UIControlEventTouchUpInside];
    [self.loginView.regist addTarget:self action:@selector(goRegist) forControlEvents:UIControlEventTouchUpInside];
    [self.loginView.findPass addTarget:self action:@selector(goFindPass) forControlEvents:UIControlEventTouchUpInside];
    
}

- (BOOL)canLog
{
    if (self.loginView.phoneNum.text.length == 0) {
        NSLog(@"phoneNumber is null");
        return NO;
    }
    if (![BCPhoneNumJuge isMobileNumber:self.loginView.phoneNum.text]) {
        NSLog(@"格式有误");
        return NO;
    }
    if (self.loginView.passWord.text.length == 0) {
        NSLog(@"密码不能为空");
        return NO;
    }
    if ([self.loginView.phoneNum.text isEqualToString:@"13812345678"]&&[self.loginView.passWord.text isEqualToString:@"2"]) {
        return YES;
    }
    return YES;

}

- (void)goLogIn
{
    if ([self canLog]) {
        AppDelegate *app = [UIApplication sharedApplication].delegate;
        app.isLogIn = YES;
    }else{
        NSLog(@"账号密码有误");
    }
}
    
- (void)goFindPass
{
    BCFindPassViewController *findPassVC = [[BCFindPassViewController alloc] init];
    [self.navigationController pushViewController:findPassVC animated:YES];
}

-(void)goRegist
{
    BCRegisterViewController *registVC = [[BCRegisterViewController alloc] init];
    [self.navigationController pushViewController:registVC animated:YES];
}

@end

